package com.lbn.jfqsc.app.alipay;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.InputFilter;
import android.widget.EditText;

import com.lbn.baseframe.base.BaseActivity;
import com.lbn.baseframe.ui.NAppbar;
import com.lbn.baseframe.utils.EasyToast;
import com.lbn.jfqsc.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class AlipayActivity extends BaseActivity<AlipayPresenter> implements IAlipayView {

    @BindView(R.id.editText)
    EditText editText;
    private int type;
    private int id;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_alipay);
        ButterKnife.bind(this);
        setAppbar(new NAppbar(this));
        appbar.openBack();
        appbar.setTitle("支付宝");
        type = getIntent().getIntExtra("type", 0);
        id = getIntent().getIntExtra("id",0);
    }


    @Override
    public AlipayPresenter createPresenter() {
        return new AlipayPresenter();
    }

    @Override
    public void onPresenterCreated() {
        super.onPresenterCreated();
        editText.setFilters(new InputFilter[]{new CashierInputFilter()});
        switch (type) {
            case 1:
                editText.setText(getIntent().getStringExtra("money"));
                editText.setClickable(false);
                editText.setEnabled(false);
                break;
            case 2:
                break;
        }
    }


    public static void startActivity(Context context,int id,String money, int type) {
        Intent intent = new Intent(context, AlipayActivity.class);
        intent.putExtra("id",id);
        intent.putExtra("money", money);
        intent.putExtra("type", type);
        context.startActivity(intent);
    }

    @Override
    public void onSucceed() {
        EasyToast.showShort(this, "支付成功");
        finish();
    }

    @OnClick(R.id.pay)
    public void onClick() {
        mPresenter.alipay(id,getMoney(),type);
    }


    public String getMoney(){
        return editText.getText().toString();
    }
}
